package com.qf.springbootopenapi.aspect;

import com.qf.springbootopenapi.exhandler.ParamNullException;
import com.qf.springbootopenapi.utils.Constants;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @BelongsProject: open-api-based-on-springboot
 * @BelongsPackage: com.qf.springbootopenapi.aspect
 * @Author: YuanSir
 * @CreateTime: 2022-10-19  15:10
 * @Description:
 * @Version: 1.0
 */


@Component
@Aspect
@Slf4j
public class NullValidateAspect {
    
    
    @Pointcut("@annotation(com.qf.springbootopenapi.annotation.NullValidation))")
    public void myPointcut(){}
    
    
    
    
    @Before("myPointcut()")
    public void before(JoinPoint jp){
        log.debug("校验参数是否为空");
        Object[] args = jp.getArgs();
    
        for (Object arg : args) {
            if (arg == null){
                log.debug("参数为空了！");
                throw new ParamNullException(Constants.ParamNull_CODE, "参数空了！");
            }
        }
    
    }
}
